<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\9\17 0017
 * Time: 14:47
 */

namespace app\command;


use app\Lib\Ioc\AdminAuth\AuthMenu;
use app\Lib\Ioc\AdminAuth\MenuManage;
use app\Lib\Ioc\Img\Img;
use app\Lib\Ioc\LotteryQualification\AddLotteryQualification;
use app\Lib\Ioc\Order\OrderOption;
use app\Lib\Ioc\Role\RoleManage;
use app\Lib\Ioc\Tag\HouseTypeTag;
use app\Lib\Ioc\Tag\StyleTagManage;
use app\Lib\Ioc\User\AdminLogin;
use app\Lib\Ioc\User\UserBase;
use app\Lib\Model\AdminAuth\GetAuthorization\GetUserAuth;
use app\Lib\Model\Order\MonitorOrderLog;
use app\Lib\Model\Order\Order;
use app\Lib\Model\Push\WeiXinPush;
use app\Lib\Model\Role\Role;
use app\Lib\Model\Role\RoleManage\GetRoleSelectList;
use app\Lib\Model\Tag\OrderStopWordReason\StopWordTagTagSelectList;
use app\Lib\Model\User\User;
use app\Lib\Model\WeiXin\GetWeiXinToken;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;

class wangcx extends  Command
{
    protected function configure()
    {

        $this->setName('wangcx')->setDescription('王淳熙专用测试');
        $this->addOption('简单测试用例', 't', Option::VALUE_OPTIONAL,
            "test--测试获取某个角色的标签 \r test2--测试用例2 \r test3--测试用例3",
            'test'); //选项值选填
        $this->addOption('roleId', 'r', Option::VALUE_OPTIONAL,
            "传递角色id填写数字",
            '1'); //选项值选填
    }

    /**
     * @param Input $input
     * @param Output $output
     */
    protected function execute(Input $input, Output $output)
    {
        $option =  $input->getOption('简单测试用例');
        $this->$option();

    }

    protected function  test1(){
        try{
            $data['opUid']='1';
            $data['menuName']='工单应用';
            $data['args']='';
            $data['action']='index';
            $data['project']='admin';
            $data['controller']='Menu';
            $data['mark']='orderTemApplications';
            $data['menuClass']='layui-icon-app';
            $data['parentId']='0';
            $data['showMenu']='1';
            $data['sortNo']='999';
            $model = new MenuManage();
            $result = $model->addMenu($data);
        }catch (\Exception $e){
            echo  $e->getMessage();
        }
    }


    protected function test2(){
        try{
            $data['account'] = 'zhuwj';
            $data['birthday'] = strtotime('1994-10-11');
            $data['e_mail'] = '591554596@qq.com';
            $data['mobilephone'] = '15671226326';
            $data['nickname'] = '朱文杰';
            $data['qq_number'] = '591554596';
            $data['reg_ip'] = '192.168.10.1';
            $data['role_id'] = '3';
            $data['sex'] = '1';
            $data['weixin_number'] ='';
            $data['opUser'] = 1;
            $ioc = new \app\Lib\Ioc\User\UserBase();
            $ioc->addAdminUserBase($data);
        }catch (\Exception $e){
            echo  $e->getMessage();
        }
    }

    protected function test3(){
        try{
            $data = [
                'opUser'=>1,
                'lotteryType'=>'zjd',
                'userMobile'=>'18680151308'
            ];
            (new AddLotteryQualification())->run($data);
        }catch (\Exception $e){
            echo  $e->getMessage();
        }
    }

    protected function test4(){
        try{
            $data = [
                'account'=>'wangcx',
                'password'=>'zjd',
                'loginIp'=>'192.168.10.1'
            ];
            (new AdminLogin())->run($data);
        }catch (\Exception $e){
            echo  $e->getMessage();
        }
    }
    protected function test7(){
        try {
            $data = [
                'loginIp' => '127.0.0.1',
                'account' => 'wangcx',
                'password' => md5(md5('anbang'.'123456') . 'anbang')
            ];
            dump((new AdminLogin())->run($data));
        }catch (\Exception $e){
            echo  $e->getMessage();
        }
    }


    protected function test8(){
        $data = (new AuthMenu())->getTopMenu();
        dump($data);
    }


    protected function test9(){
        try{
            $data['opUid'] = '1';
            $data['userAddress'] = '尚湖湾三期';
            $data['duration'] = '90';
            $data['houseType'] = '1';
            $data['introducerPhone'] = '15826962999';
            $data['orderMoney'] = '50000';
            $data['orderStyle'] = '1';
            $data['userName'] = '王先生';
            $data['userPhone'] = '18680151308';
            $model = new OrderOption();
            $result = $model->addOrder($data);
        }catch (\Exception $e){
            $str = $e->getMessage();
            $str = iconv("UTF-8", "GBK", $str);
            echo $str;
        }
//        header("Content-type:text/html; charset=utf-8");
//        echo '王淳熙';
    }

    protected function test10(){
        $data = [
            'first'=>[
                'value'=>'尊敬的朱文杰先生,您好。您在我们公司下单已成功，订单信息',
                "color"=>"#173177",
            ],
             "keyword1"=>[
                 'value'=>'阳新',
                 "color"=>"#173177",
             ],
            "keyword2"=>[
                'value'=>'雅仕兰庭',
                "color"=>"#173177",
            ],
            "keyword3"=>[
                'value'=>'现代简约风',
                "color"=>"#173177",
            ],
            'remark'=>[
                'value'=>'阳新帝豪全体员工祝您阖家幸福，生活愉快',
                "color"=>"#173177",
            ]
        ];
        $model = new WeiXinPush();
        $model->setData($data);
        $model->setTouser('oijP55uehdoSYZXIS21XtaHRB2ng');
        $model->setTemplateId('cyqkZgKgGxJmZiqQnR8WGEhIrXMO13fqzsnGTOpbJQk');
        $result = $model->run();
        dump($result);
    }

    protected function test11(){
//        $data = [
//            'name'=>'简约现代风',
//            'imgId'=>'5',
//            'opUid'=>1,
//            'id'=>1,
//        ];
//        $model = new StyleTagManage();
//        $model->editTag($data);

//        new H
        $data = [
            'name'=>'四室一厅（商品房）',
            'opUid'=>1,
            'id'=>3
        ];
        (new HouseTypeTag())->editTag($data);
//        dump((new HouseTypeTag())->getCount());
//        $data = [
//            'page'=>'1',
//            'limit'=>10,
//        ];
//        dump((new HouseTypeTag())->getList($data));
//        dump((new HouseTypeTag())->getInfo($data = ['id'=>2]));
//        $data = [
//            'page'=>'1',
//            'limit'=>10,
//        ];
//        $model = new StyleTagManage();
//        dump($model->getList($data));
    }


    protected function test12(){
//        $model =  new RoleManage();
//
//        dump($model->getPage());
//        $data = [
//          'page'=>1,
//          'limit'=>10,
//        ];
//        dump($model->getList($data));
//        dump((new GetRoleSelectList())->run());
//        dump((new RoleManage())->getInfo(['roleId'=>1]));
//        $data = [
//            'opUid'=>1,
//            'name'=>'设计总监',
//            'roleAlias'=>'designDirector',
//            'parentId'=>0,
//            'roleId'=>3,
//            'is_admin_role'=>1,
//            'auth'=>'{"0":"1","3":"4","4":"5","5":"6","6":"7","7":"8","8":"9"}'
//        ];
//        $data = '{"opUid":"1","name":"\u8bbe\u8ba1\u603b\u76d1","roleAlias":"designDirector","parentId":"0","auth":"{"0":"1","3":"4","4":"5","5":"6","6":"7","7":"8","8":"9"}","roleId":"3","is_admin_role":"1"}';
//        $data = json_decode($data,true);
//        dump($data);
//        dump((new RoleManage())->editRole($data));
//        new RoleManage()
    }

    protected function test13(){
//        $data = [
//            'keyword'=>'',
//            'keywordType'=>'',
//            'page'=>1,
//            'limit'=>10
//        ];
//        $userBase = new addUser();
//        dump($userBase->getCount($data));
//        dump($userBase->getList($data));
//        dump((new GetUserAuth(new User(1)))->run());
//        session('opIp','127.0.0.1');
//        $data = [
//            'account'=>'shifs',
//            'birthday'=>'1559923200',
//            'mobilephone'=>'15171327217',
//            'nickname'=>'石福松',
//            'role_id'=>'1',
//            'sex'=>'1',
//            'opUser'=>'1',
//            'weixin'=>'oijP55q6QwniNJJEGXFXuGHwzYns',
//            'auth'=>['1','2','3',]
//        ];
        $userBase = new UserBase();
        $data = [
            "account"=>"Mr",
            "password"=>"456789",
            "mobilephone"=>"18129977569",
            "weixin"=>"",
            "nickname"=>"梅荣",
            "birthday"=>strtotime("2019-04-24"),
            "sex"=>"2",
            "role_id"=>"2",
            "auth"=>array(
                3=>"4", 4=>"5", 5=>"6", 6=>"7", 7=>"8", 8=>"9", 9=>"10", 10=>"11",
            ),
            "account_status"=>"1",
            "id"=>"43",
            'opUser'=>1,
        ];
//        $userBase->addAdminUserBase($data);
        dump($userBase->saveUser($data));
    }

    public function test14(){
//        $model =  (new HouseTypeTag());
//        dump($model->getTagList());
//        $model = new StyleTagManage();
//        dump($model->getTagList());
//        dump((new UserBase())->getDesignUser());
        try{
            //下单
//            $data = [
//                'user_name'=>'朱文杰',
//                'user_phone'=>'15671226326',
//                'user_address'=>'太阳城三区14栋502',
//                'order_money'=>'80000',
//                'introducer_phone'=>'18680151308',
//                'duration'=>'90',
//                'user_sex'=>'1',
//                'house_type'=>'4',
//                'order_style'=>'1',
//                'design_uid'=>'2',
//                'drawing_uid'=>'2',
//                'opUid'=>1
//            ];
//            (new OrderOption())->addOrder($data);
            //选择监理
//                $data = [
//                    'opUid'=>1,
//                    'order_number'=>'2019045819',
//                    'supervisorUid'=>46,
//                    'reason'=>''
//                ];
//            (new OrderOption())->selectSiteSupervisorUid($data);
            //同意
//            $data = [
//                'order_number'=>'2019045819',
//                'opUid'=>1,
//                'review'=>1,
//                'reason'=>'测试',
//                'status'=>'',
//            ];
//            (new OrderOption())->reviewSiteSupervisorUid($data);
            //设置开工时间
//            $data = [
//                'order_number'=>'2019045819',
//                'opUid'=>'1',
//                'orderStartTime'=>'1556615090',
//            ];
//            (new OrderOption())->choiceOrderStartTime($data);
            //日志监控
//            $model = new MonitorOrderLog();
//            $model->run();
            //工地日志回复
//     $data = [
//           'order_number'=>2019045819,
//           'content'=>'这是个测试',
//                  'opUid'=>1,
//                  'log_id'=>1,
//                  'file'=>[
//                        'img'=>[
//                            [
//                                'time_id'=>0,
//                                'img_id'=>33,
//                             ],
//                            [
//                                'time_id'=>0,
//                                'img_id'=>35
//                            ],
//                        ],
//            ],
//           ];
//            $data['file'] = json_encode( $data['file']);
//         $model = new OrderOption();
//         $model->orderLog($data);
//            (new MonitorOrderLog())->pushUser();
//            $data = [
//                'opUid'=>1,
//                'keyword'=>'',
//                'keywordType'=>'',
//                'order_status'=>'',
//            ];
//            dump((new OrderOption())->getPage($data));
//            $data_1 = [
//                'opUid'=>1,
//                'keyword'=>'',
//                'keywordType'=>'',
//                'order_status'=>'',
//                'page'=>1,
//                'limit'=>10,
//            ];
//            dump((new OrderOption())->getList($data_1));
//            $model = new StopWordTagTagSelectList();
//            dump($model->getList());
            $model = new OrderOption();
            dump($model->getMySite(['opUid'=>46]));
        }catch (\Exception $exception){
//
            echo  $exception->getMessage();
        }
    }
    //监控工地日志任务

    /**
     * 监控工地日志任务
     * @throws \app\Lib\Exception\BlException
     * @throws \think\db\exception\BindParamException
     * @throws \think\exception\PDOException
     */
    public function test15(){
        $model = new MonitorOrderLog();
        $model->run();
    }

    /**
     * 工地自动开工
     * @throws \app\Lib\Exception\BlException
     * @throws \think\db\exception\BindParamException
     * @throws \think\exception\PDOException
     */
    public function test16(){
        $model = new MonitorOrderLog();
        $model->autoStartWord();
    }

    /**
     * 工单回复信息推送给业主
     * @throws \app\Lib\Exception\BlException
     */
    public function test17(){
        $model = new MonitorOrderLog();
        $model->pushUser();
    }
    public function test20(){
        (new Order(2019059054,false))->delAllCache();
    }
    /**
     * 清除缓存
     * @throws \app\Lib\Exception\BlException
//     */
//    public function test17(){
//        (new Order('2019057385'))->delAllCache();
////        (new Order('2019041291'))->delAllCache();
//    }
//    public function test18(){
////        dump((new Img())->delFile(['fileId'=>46]));
////        $data = [
////            'order_number'=>'2019041291',
////            'imgArray'=>[
////                ['id'=>0,'img_id'=>33],
////                ['id'=>0,'img_id'=>34]
////            ],
////            'url'=>[
////                'id'=>0,'url'=>'www.baidu.com'
////            ],
////            'opUser'=>1
////        ];
////        (new OrderOption())->updatePicFile($data);
////        $data = [
////            'order_number'=>'2019041291'
////            ];
////        (new OrderOption())->getPicFile($data);
//
//        $data =['opUid'=>'39'];
//        (new User(39))->delUserCache();
//        dump((new OrderOption())->getMyOrderLog($data));
//    }
    public function test18(){
        $model = new MonitorOrderLog();
        $model->monitorStop();
        return true;
    }
    public function test19(){
        $model = new OrderOption();
        $data  = ['opUid'=>51];
        $result = $model->getMyOrderLog($data);
        dump($result);
    }
}